Yes — the method show
in the superclass VideoTape
is inherited in the subclass Movie
.
The class definition for VideoTape
has a constructor that
initializes the member data of VideoTape
objects.
The class Movie
has a constructor that initializes the data of
Movie
objects.
The constructor for class Movie
looks like this:
// constructor
public Movie( String ttl, int lngth, String dir, String rtng )
{
super(ttl, lngth); // use the super class's constuctor
director = dir; rating = rtng; // initialize the members new to Movie
}
The statement super(ttl, lngth)
invokes a
constructor of the parent
to initialize some of the data.
There are two constructors in the parent.
The one that is invoked is the one that matches the argument list
in super(ttl, lngth)
.Movie
has.
Note:
When it is used,
super()
must be the first statement
in the subclass's constructor.